package com.hexinfo.dmpro.data.transfer.common.controller;

import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import com.hexinfo.dmpro.data.transfer.common.model.CustomFuncationModel;
import com.hexinfo.dmpro.data.transfer.common.service.IHiveMetadataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@AllArgsConstructor
@RequestMapping("/api/hive/metadata")
@Api(value = "HiveMetadata", tags = "HIVE元数据查询")
public class HiveMetadataController {

    @Autowired
    private IHiveMetadataService hiveMetadataService;

    @ApiOperation(value = "指定库表元数据", notes = "指定库表元数据")
    @GetMapping(value = "/{database}/{table}")
    public ResponseEntity<Object> metadata(@PathVariable("database") String database, @PathVariable("table")  String table) {
        return ResponseEntity.ok(hiveMetadataService.queryTableFields(database, table));
    }

    @ApiOperation(value = "自定义函数测试", notes = "自定义函数测试")
    @PostMapping(value = "/funcation/test")
    public ResponseEntity<Object> funcationTest(@RequestBody CustomFuncationModel customFuncationModel) {
        return ResponseEntity.ok(hiveMetadataService.funcationTest(customFuncationModel));
    }
}
